package com.ebs.md.fxmonitor.marketmonitor.model;

/**
 * Perforce Revision:
 *  $File: //depot/MarketData/fxmonitor/main/src/main/java/com/ebs/md/fxmonitor/marketmonitor/model/AbsOBChange.java $
 *  $Revision: #10 $  $Change: 115868 $  $DateTime: 2012/10/17 13:08:52 $  $Author: Arik.Sher $
 */

import java.io.Serializable;

import com.ebs.md.api.BookSide;
import com.ebs.md.api.IDetailedBookEntry;
import com.ebs.md.api.Rate;
import com.ebs.md.api.orderbook.BookEntryPosition;
import com.ebs.md.api.orderbook.BookEntryPositionOfDeleted;
import com.ebs.md.api.product.PairProduct;


public abstract class AbsOBChange
implements Serializable
{
	// gened with Eclipse
	private static final long serialVersionUID = 1345722567057300202L;

	protected long      timestamp; // id 1#2, milliseconds since 1970
	protected String    quoteId;   // id 2#2

	protected PairProduct pair;    
	protected BookSide    bookSide;
	
	/**
	 * firmId. 
	 * taken from nodes.bin - field virtualFloorId
	 * 
	 * when 0 than it is not set.
	 */
	protected int    firmId = 0;
	protected String dealCode;
	protected String traderId;

	protected String    region;
	protected Rate      rate;
	
	protected long      availAmount;
	protected long      totalAmount;
	protected long      displayAmount;
	
	protected int       obPosition;
	protected int       obEntriesAtPosition;
	
	// gened with Eclipse on quoteId and timestamp
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((quoteId == null) ? 0 : quoteId.hashCode());
		result = prime * result + (int) (timestamp ^ (timestamp >>> 32));
		return result;
	}
	// gened with Eclipse on quoteId and timestamp
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		AbsOBChange other = (AbsOBChange) obj;
		if (quoteId == null) {
			if (other.quoteId != null)
				return false;
		} else if (!quoteId.equals(other.quoteId))
			return false;
		if (timestamp != other.timestamp)
			return false;
		return true;
	}

	public AbsOBChange(long timestamp, String quoteId, PairProduct pair,
			BookSide bookSide, String dealCode, String traderId, Rate rate,
			long availAmount, int obPosition, int obEnriesAtPosition
		  , long totalAmount, long displayAmount, String region, int firmId
	) {
		super();
		this.timestamp = timestamp;
		this.quoteId = quoteId;
		this.pair = pair;
		this.bookSide = bookSide;
		this.dealCode = dealCode;
		this.traderId = traderId;
		this.rate = rate;
		this.availAmount = availAmount;
		this.obPosition = obPosition;
		this.obEntriesAtPosition = obEnriesAtPosition;
		this.totalAmount = totalAmount;
		this.displayAmount = displayAmount;
		this.region = region;
		this.firmId = firmId;
	}
	
	public AbsOBChange(long timestamp, String quoteId, PairProduct pair,
			BookSide bookSide, String dealCode, String traderId, Rate rate,
			long availAmount, int obPosition, int obEnriesAtPosition, String region, int firmId)
	{
		this(timestamp, quoteId, pair, bookSide, dealCode, traderId, rate, availAmount, obPosition, obEnriesAtPosition
			,availAmount, availAmount, region, firmId
			);
	}


	public AbsOBChange(PairProduct pair, IDetailedBookEntry be, BookEntryPosition bep, int firmId) {
		super();
		this.pair = pair;
		this.timestamp = be.getQuoteTime().getTimeInMillis();
		this.quoteId = be.getQuoteId();
		this.bookSide = be.getSide();
		this.dealCode = be.getDealCode();
		this.traderId = be.getTraderId();
		this.rate     = be.getRate();
		this.availAmount = be.getAmount();
		this.totalAmount = be.getTotalAmount();
		this.displayAmount = be.getDisplayAmount();
		this.obPosition = bep.getPosition();
		this.obEntriesAtPosition = bep.getEntriesAtPosition();
		this.region = be.getRegion();
		this.firmId = firmId;
	}
	
	public AbsOBChange(PairProduct pair, IDetailedBookEntry be, BookEntryPositionOfDeleted bep, int firmId) {
		super();
		this.pair = pair;
		this.timestamp = be.getQuoteTime().getTimeInMillis();
		this.quoteId = be.getQuoteId();
		this.bookSide = be.getSide();
		this.dealCode = be.getDealCode();
		this.traderId = be.getTraderId();
		this.rate     = be.getRate();
		this.availAmount = be.getAmount();
		this.totalAmount = be.getTotalAmount();
		this.displayAmount = be.getDisplayAmount();
		this.obPosition = bep.getPosition();
		this.obEntriesAtPosition = bep.getEntriesAtPosition();
		this.region = be.getRegion();
		this.firmId = firmId;
	}
	
	public long getTimestamp() {
		return timestamp;
	}
	public String getQuoteId() {
		return quoteId;
	}
	public PairProduct getPair() {
		return pair;
	}
	public BookSide getBookSide() {
		return bookSide;
	}
	public int getFirmId() {
		return firmId;
	}
	public String getDealCode() {
		return dealCode;
	}
	public String getTraderId() {
		return traderId;
	}
	public String getRegion() {
		return region;
	}
	public Rate getRate() {
		return rate;
	}
	public long getAvailAmount() {
		return availAmount;
	}
	public long getTotalAmount() {
		return totalAmount;
	}
	public long getDisplayAmount() {
		return displayAmount;
	}
	public int getObPosition() {
		return obPosition;
	}
	public int getObEntriesAtPosition() {
		return obEntriesAtPosition;
	}

	public boolean isAtObBest() {
		return obPosition == 1;
	}
	
	public void setTotalAmount(long totalAmount) {
		this.totalAmount = totalAmount;
	}

	public boolean hasFirmId() {
		// firmId = 0 means noFirmId
		return firmId > 0;
	}
	// meet the java standard for boolean getter ("isXXXX")
	public boolean isHasFirmId() {
		return hasFirmId();
	}

	protected final String shortClassName = getClass().getSimpleName();
	
	protected abstract String additionalFields4toString();
	
	public String toString() {
//		return "OBChange" +
		return shortClassName +
				" [availAmount=" + availAmount + ", bookSide="
				+ bookSide + ", dealCode=" + dealCode + ", firmId=" + firmId
				+ ", obPosition=" + obPosition + ", obEntriesAtPosition=" + obEntriesAtPosition
				+ ", pair=" + pair
				+ ", quoteId=" + quoteId + ", rate=" + rate + ", region="
				+ region + ", timestamp=" + timestamp
				+ ", traderId=" + traderId 
				+ ", totalAmount=" + totalAmount + ", displayAmount=" + displayAmount
				+ additionalFields4toString()
				+ "]";
	}
	
}
